package clazz;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * @description:
 * @author: Lidong
 * @time: 2020/5/23 16:46
 **/
public class ClassLoaderTest {

    private static final Logger logger = LoggerFactory.getLogger(ClassLoaderTest.class);

    public static void main(String[] args) {
        //获取系统类加载器
        ClassLoader systemClassLoader = ClassLoader.getSystemClassLoader();
        logger.info(String.valueOf(systemClassLoader));

        //获取其上层：扩展类加载器
        ClassLoader classLoader = systemClassLoader.getParent();
        logger.info(String.valueOf(classLoader));

        //获取其上层：获取不到其上层引导类加载器
        ClassLoader bootstrapLoader = classLoader.getParent();
        logger.info(String.valueOf(bootstrapLoader));

        //对于用户自定义类：默认使用系统类加载器来加载
        ClassLoader classLoader1 = ClassLoaderTest.class.getClassLoader();
        logger.info(String.valueOf(classLoader1));

        //String使用引导类加载器加载。--->java的核心类库都是使用引导类加载器进行加载的
        ClassLoader classLoader2 = String.class.getClassLoader();
        logger.info(String.valueOf(classLoader2));
    }
}
